<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
    <META HTTP-EQUIV="Pragma" CONTENT="no-cache">
    <meta name="viewport"
          content="initial-scale=1.0,maximum-scale=1.0,minimum-scale=1.0,user-scalable=no,width=device-width"/>
    <meta name="format-detection" content="telephone=no"/>
    <meta name="app-mobile-web-app-capable" content="yes"/>
    <meta name="app-mobile-web-app-status-bar-style" content="black-translucent"/>
    <link rel="stylesheet" href="//at.alicdn.com/t/font_772560_nyw5t78j0pd.css">
    <link rel="stylesheet" href="css/add-member.css">
</head>
<body>
<div id="app" v-cloak>
    <ul>
        <li class="member flex align" v-for="item in list">
            <input type="checkbox" :value="item.id" v-model="names">
            <img :src="item.face_url" alt="">
            <p class="name">{{item.name}}</p>
        </li>
    </ul>
    <div style="height:60px"></div>
    <div class="btn-wrap">
        <div class="button" @click="createTag">确定</div>
    </div>
</div>
<script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script>

    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
    <script src="https://cdn.bootcss.com/vue/2.5.17-beta.0/vue.min.js"></script>
    <script type="text/javascript">
        var app=new Vue({
            el:'#app',
            data:{
                list:[],
                names:[],
                type:'',
                tagId:''
            },
            created: function () {
                this.loadData()
            },
            methods:{
                GetQueryString:function (id) {
                    {
                        var reg = new RegExp("(^|&)"+ id +"=([^&]*)(&|$)");
                        var r = decodeURI(window.location.search.substr(1)).match(reg);
                        if(r!=null)return  unescape(r[2]); return null;
                    }
                },
                loadData:function () {
                    var id = sessionStorage.getItem('login_identifier')
                    this.tagId=this.GetQueryString('id')
                    this.type=this.GetQueryString('type')
                    axios({
                        url:'https://qyim.ec51.com/v1/check/get-customer-by-tag',
                        method:'get',
                        params :{
                            id:id,
                            tagID:this.tagId,
                            type:this.type,
                        }
                    }).then(res=>{
                        this.list=res.data.data
                    })
                },
                createTag:function(){
                    this.name=this.GetQueryString('name')
                    var fd=new FormData()
                    fd.append('id',sessionStorage.getItem('login_identifier'))
                    fd.append('customers',this.names)
                    fd.append('tag',this.name||this.tagId)
                    fd.append('type',this.type)
                    axios.post('https://qyim.ec51.com/v1/check/create-tag',fd).then(res=>{
                        if(res.data.status.message!='ok'){
                            alert(res.data.status.message)
                        }
                        history.go(-2)

                    })
                },
            }
        })


    </script>
</body>
</html>